<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE HTML>
<html>
<head>
	<!DOCTYPE html>
<html class="no-js">
<head>
	<meta name="author" content="蓝凌科技">
	<meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
	<meta name="renderer" content="webkit"/>
	<meta http-equiv="Cache-Control" content="no-siteapp" />
	<link href="/Public/Blovex4/css/amazeui.css" rel="stylesheet">
	<link href="/Public/Blovex4/css/amaze.css" rel="stylesheet">
	<link href="/Public/Blovex4/css/admin.css" rel="stylesheet">
	<link href="/Public/Blovex4/css/jquery.datetimepicker.css" rel="stylesheet">
	<link href="/Public/Blovex4/css/custom.css" rel="stylesheet">
	<link href="/Public/Common/css/amazeui.datetimepicker.css" rel="stylesheet">
	<title><?php echo C('WEB_SITE_TITLE');?></title>
	
	<script type="text/javascript">
	    var _root = '<?php echo ($_site_url); echo U(' / ');?>', _controller = '<?php echo ($_controller); ?>';
	</script>
	
	
<link href="/Public/Blovex4/css/jquery.datetimepicker.css" rel="stylesheet">


	<!-- 页面header钩子，一般用于加载插件CSS文件和代码 -->


</head>
<body  style="overflow:hidden;">
	<!-- 头部 -->
	<!-- 导航条
================================================== -->
<header id="amz-header" class="am-topbar am-topbar-fixed-top" >
    <div class="am-g">
        <div class="col-md-2 am-u-md-2">
            <h1>
            	<a href="#" target="_blank">帮工小哥</a>
            	<span class="am-badge am-badge-danger"><?php echo (C("APP_VERSION")); ?></span>
            </h1>
        <button class="am-topbar-btn am-topbar-toggle am-btn am-btn-sm am-btn-success am-show-sm-only" data-am-collapse="{target: '#topbar-collapse'}">
            <span class="am-sr-only">导航切换</span>
            <span class="am-icon-bars"></span>
        </button>
		</div>
        
        <div class="col-md-10 am-u-md-10">
           
            <div class="am-collapse am-topbar-collapse" id="topbar-collapse">
            	<ul class="amz-header-nav am-topbar-nav">
                    <?php if(is_array($__MENU__['main_menu'])): foreach($__MENU__['main_menu'] as $key=>$vo): ?><li>
                            <a href="<?php echo (U($vo["menu_url"])); ?>" style="outline:none;"><?php echo ($vo["menu_name"]); ?></a>
                        </li><?php endforeach; endif; ?>
                   
                </ul>
                <ul class="am-nav am-nav-pills am-topbar-nav am-topbar-right admin-header-list">
                    <li>
                        <a href="<?php echo U('Public/logout');?>"><span class="am-icon-sign-out" style="color:white;">注销</span></a>
                    </li>
                </ul>
            </div>
        </div>
    </div>
</header>


<link href="/Public/Blovex4/css/jquery.datetimepicker.css" rel="stylesheet">


	<!-- /头部 -->
	
	<!-- 主体 -->
	<div class="am-cf am-g">
    <!--左边开始---->
    <div class="am-u-sm-2 am-u-md-2 am-u-lg-2 admin-sidebar am-offcanvas am-offcanvas-style" id="admin-offcanvas">
        <div class="am-offcanvas-bar admin-offcanvas-bar left-style" >
   
	<div class="am-g admin-style">
        <div class="am-u-sm-4">
            <a href="#" class="am-icon-btn am-secondary  am-icon-drupal"></a>
        </div>
        <div class="am-u-sm-8">
            <?php echo ($ADMIN_NAME); ?>
            <br/>
            <a style="cursor:pointer;" title="退出" href="<?php echo U('Public/logout');?>"><span class="am-icon-power-off"></span></a>
            &nbsp; <a style="cursor:pointer;" title="修改密码" href="<?php echo U('Index/updatePassword');?>"><span class="am-icon-lock"></span></a>
        </div>
    </div>
    <ul class="am-list" >
        <?php if(is_array($__MENU__['_child'])): foreach($__MENU__['_child'] as $key=>$sub_menu): if(!empty($sub_menu)): ?><li>
            <a href="<?php echo (U($sub_menu["menu_url"])); ?>"><span class="<?php echo ((isset($sub_menu["menu_icon"]) && ($sub_menu["menu_icon"] !== ""))?($sub_menu["menu_icon"]):''); ?>">&nbsp;</span><?php echo ($sub_menu["menu_name"]); ?><span class="<?php echo ((isset($sub_menu["menu_style"]) && ($sub_menu["menu_style"] !== ""))?($sub_menu["menu_style"]):''); ?>"></span></a>
            <?php if(is_array($sub_menu['_child'])): foreach($sub_menu['_child'] as $key=>$menuname): ?><li class="am-margin-horizontal">
                    <a href="<?php echo (U($menuname["menu_url"])); ?>"><span class="<?php echo ((isset($menuname["menu_icon"]) && ($menuname["menu_icon"] !== ""))?($menuname["menu_icon"]):''); ?>">&nbsp;</span><?php echo ($menuname["menu_name"]); ?><span class="<?php echo ((isset($menuname["menu_style"]) && ($menuname["menu_style"] !== ""))?($menuname["menu_style"]):''); ?>"></span></a>
                </li><?php endforeach; endif; endif; ?>
        </li><?php endforeach; endif; ?>
    </ul>
</div>

    </div><!--左边结束---->
    <div class="am-u-sm-10 am-u-md-10 am-u-lg-10 custom-left am-fr" id="Contename"   >
        <div id="top-alert" class="fixed alert alert-error am-u-sm-12 am-u-md-12" style="display:none">
            <button class="close fixed" style="margin-top: 4px;">
                &times;
            </button>
            <div class="alert-content">
                这是内容
            </div>
        </div>
        
	<div class="am-cf am-padding-top">
        <div class="am-fl am-cf">
            <i class="am-icon-pencil-square-o"></i>
            <strong class="am-text-primary am-text-lg">
                    新增订单
            </strong>
        </div><hr data-am-widget="divider" class="am-divider am-divider-default" />
    </div>
    <div class="am-tabs" data-am-tabs>
        <ul class="am-tabs-nav am-nav am-nav-tabs">
            <li>
                <a href="#tab2">订单信息</a>
            </li>
        </ul>
        <div class="am-tabs-bd">
            <div class="am-tab-panel am-fade" id="tab2">
                <form class="am-form" method="post" action="<?php echo U('Orders/saveAction');?>">
                    <div class="am-g am-margin-top">
                        <div class="am-u-sm-4 am-u-md-2 am-text-right">
                            用户账号
                        </div>
                        <div class="am-u-sm-8 am-u-md-4 am-u-end col-end">
                            <input type="text" class="am-input-sm js-ajax-validate" name="account" id="account"
                            	  value="<?php echo ($userModel['account']); ?>" placeholder="用户注册手机号" required>
                            <input type="hidden" class="am-input-sm" name="user_id" id="user_id" value="<?php echo ($userModel['user_id']); ?>">
                        </div>
                        <div class="am-hide-sm-only am-u-md-6">
                        </div>
                    </div>
                    <div class="am-g am-margin-top">
                        <div class="am-u-sm-4 am-u-md-2 am-text-right">
                            服务类型
                        </div>
                        <div class="am-u-sm-8 am-u-md-4">
                            <select data-am-selected="{btnSize: 'sm', btnStyle: 'secondary',maxHeight: 200}" 
                            	name="detail_id" id="detail_id">
                                <?php if(is_array($detailList)): foreach($detailList as $key=>$class): ?><optgroup label="<?php echo ($class["class_name"]); ?>">
                                    <?php if(!empty($class['_child'])): if(is_array($class['_child'])): foreach($class['_child'] as $key=>$detail): ?><option value="<?php echo ($detail["detail_id"]); ?>" emergency="<?php echo ($detail["emergency"]); ?>"><?php echo ($detail["detail_name"]); ?></option><?php endforeach; endif; endif; ?>
                                    </optgroup><?php endforeach; endif; ?>
                            </select>
                        </div>
                        <div class="am-hide-sm-only am-u-md-6">
                        </div>
                    </div>
                    <div class="am-g am-margin-top">
                        <div class="am-u-sm-4 am-u-md-2 am-text-right">
                            预约类型
                        </div>
                        <div class="am-u-sm-8 am-u-md-4">
                            <select name="emergency" id="emergency" disabled>
                            	<option value="1" selected>预约服务</option>
                                <option value="2">紧急服务</option>
                            </select>
                        </div>
                        <div class="am-hide-sm-only am-u-md-6">
                        </div>
                    </div>
                    <div class="am-g am-margin-top" style="display:none;" id="delaydiv">
                        <div class="am-u-sm-4 am-u-md-2 am-text-right">
                            紧急时间
                        </div>
                        <div class="am-u-sm-8 am-u-md-4">
                            <select name="delay" id="delay">
                            	<option value="50" selected>50分钟</option>
                                <option value="40">40分钟</option>
                                <option value="30">30分钟</option>
                                <option value="20">20分钟</option>
                            </select>
                        </div>
                        <div class="am-hide-sm-only am-u-md-6">
                        </div>
                    </div>
                    
                    <div class="am-g am-margin-top" id="workerdiv">
                        <div class="am-u-sm-4 am-u-md-2 am-text-right">
                            指定小哥
                        </div>
                        <div class="am-u-sm-8 am-u-md-4 am-u-end col-end">
                            <input type="text" class="am-input-sm" name="eid" id="eid"
                            	  value="" placeholder="小哥工号">
                        </div>
                        <div class="am-hide-sm-only am-u-md-6">
                        </div>
                    </div>
                    <div class="am-g am-margin-top" id="appointdiv">
						<div class="am-u-sm-4 am-u-md-2 am-text-right">
                                预约时间:
                        </div>
                        <div class="am-u-sm-8 am-u-md-4 am-u-end col-end">
                            <input type="text" class="am-form-field am-input-sm" readonly="readonly"
                            	name="appointment" style="cursor:pointer;width:100%" 
                            	id="appointment" datetimepicker>
                        </div>
                        <div class="am-hide-sm-only am-u-md-6" id="timediv">
                        </div>
                    </div>
                    <div class="am-g am-margin-top">
                        <div class="am-u-sm-4 am-u-md-2 am-text-right">
                            维修地址
                        </div>
                        <div class="am-u-sm-8 am-u-md-4">
                            <select name="address_id" id="address_id">
                            	<option value="">请选择维修地址</option>
                                <?php if(is_array($list)): foreach($list as $key=>$address): ?><option value="<?php echo ($address["address_id"]); ?>" contact="<?php echo ($address["contact"]); ?>" tel="<?php echo ($address["telphone"]); ?>"
                                    	address="<?php echo ($address["address"]); ?>"
                                    	<?php if(address.default_address == '1'): ?>selected<?php endif; ?>>
                                    	<?php echo ($address["address"]); ?>
                                    </option><?php endforeach; endif; ?>
                                <option value="-1">其它</option>
                            </select>
                        </div>
                        <div class="am-hide-sm-only am-u-md-6">
                        </div>
                    </div>
                    <div class="am-g am-margin-top">
                        <div class="am-u-sm-4 am-u-md-2 am-text-right">
                            联系人姓名
                        </div>
                        <div class="am-u-sm-8 am-u-md-4">
                            <input type="text" class="am-input-sm" name="contact" id="contact" value="" required/>
                        </div>
                        <div class="am-hide-sm-only am-u-md-6">
                        </div>
                    </div>
                    <div class="am-g am-margin-top">
                        <div class="am-u-sm-4 am-u-md-2 am-text-right">
                            联系电话
                        </div>
                        <div class="am-u-sm-8 am-u-md-4">
                            <input type="text" class="am-input-sm" name="telphone" id="telphone"
                            	 pattern="^1(3|4|5|7|8)\d{9}$" value="" required/>
                        </div>
                        <div class="am-hide-sm-only am-u-md-6">
                        </div>
                    </div>
                    <div class="am-g am-margin-top">
                        <div class="am-u-sm-4 am-u-md-2 am-text-right">
                            详细地址
                        </div>
                        <div class="am-u-sm-8 am-u-md-4">
                        	<div class="am-input-group am-input-group-sm">
			                    <input type="text" class="am-form-field am-input-sm" 
			                    	placeholder="详细地址" name="address" id='address' value="" required/>
			                    <span class="am-input-group-btn">
			                        <button class="am-btn am-btn-default" type="button" onclick="codeAddress()">
			                            搜索
			                        </button>
			                    </span>
			                </div>
                        </div>
                        <div class="am-hide-sm-only am-u-md-6">
                        </div>
                    </div>
                    <div class="am-g am-margin-top">
                        <div class="am-u-sm-4 am-u-md-2 am-text-right">
                        </div>
                        <div class="am-u-sm-8 am-u-md-8">
                        	<div name="container" id="container" style="height:300px"></div>
                        </div>
                        <div class="am-hide-sm-only am-u-md-2">
                        </div>
                    </div>
                    <div class="am-margin">
                        <button type="submit" class="am-btn am-btn-success am-btn-xs ajax-post" target-form="am-form">
                            提交保存
                        </button>
                        <button type="button" class="am-btn am-btn-secondary am-btn-xs" onclick="javascript:history.back(-1);return false;">
                            返回列表
                        </button>
                        <input type="hidden" name="worker_id" id="worker_id" value="" />
                        <input type="hidden" name="province" id="province" value="<?php echo ($addressModel['province']); ?>" />
                        <input type="hidden" name="city" id="city" value="<?php echo ($addressModel['city']); ?>" />
                        <input type="hidden" name="district" id="district" value="<?php echo ($addressModel['district']); ?>" />
                        <input type="hidden" name="latitude" id="latitude" value="<?php echo ((isset($addressModel['latitude']) && ($addressModel['latitude'] !== ""))?($addressModel['latitude']):'39.98752'); ?>" />
                        <input type="hidden" name="longitude" id="longitude" value="<?php echo ((isset($addressModel['longitude']) && ($addressModel['longitude'] !== ""))?($addressModel['longitude']):'116.41945'); ?>" />
                    </div>
                </form>
            </div>
        </div>
    </div>

    </div>
</div>
<a class="am-icon-btn am-icon-th-list am-show-sm-only admin-menu" data-am-offcanvas="{target: '#admin-offcanvas'}"
  style="z-index:980;"></a>
</body>

</html>

	<!-- /主体 -->

	<!-- 底部 -->
	<!-- 底部
================================================== -->
<footer>
</footer>
<script type="text/javascript">
    (function(){
        var ThinkPHP = window.Think = {
            "ROOT"   : "", //当前网站地址
            "APP"    : "/blovex4.php?s=", //当前项目地址
            "PUBLIC" : "/Public", //项目公共目录地址
            "DEEP"   : "<?php echo C('URL_PATHINFO_DEPR');?>", //PATHINFO分割符
            "MODEL"  : ["<?php echo C('URL_MODEL');?>", "<?php echo C('URL_CASE_INSENSITIVE');?>", "<?php echo C('URL_HTML_SUFFIX');?>"],
            "VAR"    : ["<?php echo C('VAR_MODULE');?>", "<?php echo C('VAR_CONTROLLER');?>", "<?php echo C('VAR_ACTION');?>"]
        }
    })();
</script>
<!--[if lt IE 9]>
    <script src="/Public/Blovex4/js/jquery-1.8.min.js"></script>
    <script src="http://cdn.staticfile.org/modernizr/2.8.3/modernizr.js"></script>
	<script src="/Public/Blovex4/js/polyfill/rem.min.js"></script>
	<script src="/Public/Blovex4/js/polyfill/respond.min.js"></script>
    <script src="/Public/Blovex4/js/amazeui.legacy.js"></script>
<![endif]-->
<!--[if (gte IE 9)|!(IE)]><!-->
    <script type="text/javascript" src="/Public/Common/js/jquery-2.0.3.min.js">
    </script>
    <script type="text/javascript" src="/Public/Common/js/amazeui.min.js">
    </script>
<!--<![endif]-->
<script src="/Public/Common/js/jquery.datetimepicker.js" type="text/javascript">
</script>
<script src="/Public/Blovex4/js/think.js" type="text/javascript">
</script>
<script src="/Public/Blovex4/js/custom.js" type="text/javascript">
</script>
<script src="/Public/Common/js/jquery.nicescroll.js" type="text/javascript">
</script>


<script type="text/javascript" src="/Public/Common/js/map.js"></script>
<script type="text/javascript" src="/Public/Common/js/jquery.datetimepicker.js"></script>
<script type="text/javascript">

window.onload = loadScript;

$(function() {
	
	Think.setValue('address_id', '<?php echo ($address_id); ?>');
	
	var timeList = [];
	
	$('.am-form').validator({
		validate: function(validity) {
			var v = $(validity.field).val();
			
			var comparer = function(data) {
				if(data.status == 0){
	    			validity.valid = false;
	    			$("#address_id option[value!='']").remove();
	    		}else{
	    			var html = '<option value="">请选择维修地址</option>';
	    			var checked = '';
	    			$.each(data.info, function(k,v){
	    				checked = v['default_address'] == '1' ? ' checked ' : '';
	    				html += '<option value="' + v['address_id'] + '" contact="' + v['contact'] + '" ';
	    				html += 'tel="' + v['telphone'] + '" address="' + v['address'] + '" ' + checked + '>';
	    				html += v['address'] + '</option>';
	    			});
	    			
	    			html += '<option value="-1">其它</option>';
	    			
	    			$("#address_id").html(html);
	    		}
			};
			
			var time = function(data){
				
				if(data.status == 0){
					
					validity.valid = false;
					$("#timeList").html('未查到小哥信息');
					$("#worker_id").val('0');
				}else{
					$("#timeList").html('');
					$("#appointment").val('');
					$("#worker_id").val(data.status);
				}
				
				$.each(data.info, function(k,v){
					$.each(v['timeList'], function(t, m){
						if(m['status'] == '4'){
							timeList.push('' + m['timestamp']);
						} 
					})
				});
			};
			
			// Ajax 验证注册账号是否存在
		    if ($(validity.field).is('.js-ajax-validate')) {
		    	var account = $("#account").val();
		    	var validityURL = Think.U('Orders/validity');
		    	
		    	if(!(/^1((3|4|5|8){1}\d{1}|70)\d{8}$/.test(account))){
		    		validity.valid = false;
		    	}else{
			    	return $.ajax({
			            url: validityURL,
			            cache: false,
			            data:{'account':account},
			            dataType: 'json'
			        }).then(function(data) {
			            comparer(data);
			            return validity;
			        }, function() {
			        	return validity;
			        });
		    	}
			}else if ($(validity.field).is('#eid')) {
				
				var eid = $("#eid").val();
				var workerURL = Think.U('Orders/queryWorker');
				
				if(eid != ""){
					
					return $.ajax({
			            url: workerURL,
			            cache: false,
			            data:{'eid':eid},
			            dataType: 'json'
			        }).then(function(data) {
			        	time(data);
			            return validity;
			        }, function() {
			        	return validity;
			        });
				}else{
					return true;
				}
			}else if ($(validity.field).is('#appointment')) {
				
				var timestamp = strTotimeStamp(v);

				if($.isArray(timeList) && timeList.length > 0 && $.inArray('' + timestamp, timeList) == -1){
					validity.valid = false;
					$("#timediv").html('预约时间有冲突，请重新选择时间');
				}else{
					$("#timediv").html('');
				}
			}
		},
		
		submit: function() {
			
		    var formValidity = this.isFormValid();

		    $.when(formValidity).then(function() {
		      // 验证成功的逻辑
		      alert('成功');
		    }, function() {
		      // 验证失败的逻辑
		      alert('失败');
		    });
		}
	});
	
	$("#address_id").change(function(){
		
		var val = $(this).children('option:selected').val();
		
		if(!isNaN(val)){
			
			var address = $(this).children('option:selected').attr('address');
			var contact = $(this).children('option:selected').attr('contact');
			var telphone = $(this).children('option:selected').attr('tel');
			
			$('#contact').val(contact);
			$('#telphone').val(telphone);
			$('#address').val(address);
		}
	});
	
	$("#detail_id").off('change').on('change', function(){
		var emergency = $(this).find('option').eq(this.selectedIndex).attr('emergency');
		
		if(emergency == 1){
			$("#emergency").removeAttr('disabled');
		}else{
			$("#emergency").val('1');
			$("#emergency").trigger('change');
			$("#emergency").attr('disabled', 'disabled');
		}
		
		return false;
	});
	
	$("#emergency").off('change').on('change', function(){
		
		var emergency = $(this).val();
		
		if(emergency == 1){
			$("#delaydiv").css('display', 'none');
			$("#workerdiv").css('display', 'block');
			$("#appointdiv").css('display', 'block');
			$("#eid").val('');
			$("#eid").trigger('change');
		}else{
			$("#eid").val('');
			$("#eid").trigger('change');
			$("#workerdiv").css('display', 'none');
			$("#appointdiv").css('display', 'none');
			$("#delaydiv").css('display', 'block');
		}
	});
	
	var timePicker = $("#appointment").datetimepicker({
        datepicker: true,
        startDate: new Date().toLocaleString(),
        format: 'Y-m-d H:i',
        step: 60,
        minView:1,
        lang:'ch'
    });
});

function formatDate(timeStamp){
	
	var localTime = new Date(timeStamp * 1000);
	var year = localTime.getFullYear();
	var month = parseInt(localTime.getMonth()) + 1;
	var date = localTime.getDate();

	return year + '.' + month + '.' + date;
}

function formatHour(timeStamp){
	
	var localTime = new Date(timeStamp * 1000);
	var hour = localTime.getHours();
	
	return checkTime(hour) + ':00';
}

function checkTime(i){
	if (i<10){
        i = "0" + i;
    }
    return i;
}

function strTotimeStamp(str) {
	var tempStrs = str.split(" ");
	var dateStrs = tempStrs[0].split("-");
	var year = parseInt(dateStrs[0], 10);
	var month = parseInt(dateStrs[1], 10) - 1;
	var day = parseInt(dateStrs[2], 10);
	var timeStrs = tempStrs[1].split("-");
	var hour = parseInt(timeStrs [0], 10);
	hour = isNaN(hour) ? 14 : hour;
	var date = new Date(year, month, day, hour, 0, 0);
	
	var timestamp = date.getTime().toString();
	return timestamp.substr(0, 10);
}
</script>


<!-- 用于加载js代码 -->


	<!-- /底部 -->
</body>
</html>